package com.base.service;

import com.achievement.service.impl.*;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.base.entity.bo.SciencePersonBo;
import com.base.entity.bo.User;
import com.base.entity.bo.UserEntity;
import com.base.entity.vo.SciencePersonVo;
import com.base.mapper.SciencePersonMapper;
import com.base.mapper.UserMapper;
import com.base.utils.CutPageBean;
import com.common.api.ApprovalApi;
import com.common.core.domain.AjaxResult;
import com.common.core.domain.entity.ProcessConfig;
import com.common.core.domain.entity.SysDept;
import com.common.core.domain.entity.SysUser;
import com.common.core.domain.model.LoginUser;
import com.common.core.service.ProcessConfigService;
import com.common.utils.CurrentRoleUtils;
import com.common.utils.SecurityUtils;
import com.common.utils.StringUtils;
import com.common.utils.bean.BizProcessMessages;
import com.common.utils.uuid.IdUtils;
import com.feemanage.service.impl.cWIncomeClaimServiceImpl;
import com.flowable.domain.vo.FlowQueryVo;
import com.flowable.domain.vo.task.BpmTaskApproveReqVO;
import com.flowable.service.IFlowTaskService;
import com.framework.web.service.TokenService;
import com.system.service.ISysDeptService;
import com.system.service.ISysRoleService;
import com.system.service.ISysUserService;
import com.system.service.impl.SysRoleServiceImpl;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class SciencePersonService {
    @Autowired
    SciencePersonMapper sciencePersonMapper;

//    @Autowired
//    ProjectInitServiceImpl projectInitService;

    @Autowired
    UserMapper userMapper;

    @Autowired
    ISysUserService iSysUserService;

    @Autowired
    ISysRoleService iSysRoleService;

    @Autowired
    StandardServiceImpl standardService;

    @Autowired
    cWIncomeClaimServiceImpl cWIncomeClaimService;

    @Autowired
    MedicineServiceImpl medicineService;

    @Autowired
    PatentServiceImpl patentService;

    @Autowired
    CopyRightServiceImpl copyRightService;

    @Autowired
    BreedServiceImpl breedService;

    @Autowired
    ProductTransformServiceImpl productTransformService;

    //流程引擎
    @Autowired
    private IFlowTaskService flowTaskService;

    @Autowired
    SysRoleServiceImpl  sysRoleService;

    @Autowired
    private ApprovalApi approvalApi;

    //流程配置
    @Autowired
    private ProcessConfigService processService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private ISysDeptService deptService;

    /**角色正常状态*/
    public static final long ROLE_BIZ_KYRY_ID = 101;
    public static final long ROLE_BIZ_KYMS_ID = 102;
    public static final long ROLE_BIZ_KYCGLY_ID = 103;
    public static final long ROLE_BIZ_PSZJ_ID = 104;


    public CutPageBean<SciencePersonBo> getPersonList(SciencePersonVo sciencePersonVo) {
        String currentRoleKey = CurrentRoleUtils.getCurrentRoleKey();
        if(currentRoleKey.equals("biz_kyms")){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            String[] unitAdminScopeRealList = user.getUnitAdminScopeReal().split(",");
            sciencePersonVo.setUnitAdminScopeRealList(unitAdminScopeRealList);
        }
        sciencePersonVo.setStart(sciencePersonVo.getPage(),sciencePersonVo.getPageSize());
        CutPageBean<SciencePersonBo> cutPage = new CutPageBean<>();
        List<SciencePersonBo> list = sciencePersonMapper.selectPersonList(sciencePersonVo);
        int count = sciencePersonMapper.selectPersonCount(sciencePersonVo);
        cutPage.initCutPage(count,sciencePersonVo.getPageSize(),list);
        return cutPage;
    }

    public  int deletPersonList(SciencePersonBo sciencePersonBo) {
        SciencePersonVo sciencePersonVo=new SciencePersonVo();
        sciencePersonVo.setId(sciencePersonBo.getId());
        List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
        List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
        iSysUserService.deleteUserById(userId.get(0));
        int row=sciencePersonMapper.deleteById(sciencePersonBo);
        return row;
    }

    public  AjaxResult insertPersonList(SciencePersonBo sciencePersonBo) {
        String processInstanceId = "";
        if(sciencePersonBo != null){
            Integer submitType = sciencePersonBo.getSubmitType();
            switch (submitType) {
                case -1: {
                    //暂存：新建编辑都只保存信息，不做任何其他操作
                    Integer account=sciencePersonMapper.accountList(sciencePersonBo);
                    if(account>0){
                       return AjaxResult.error(BizProcessMessages.ACCOUNT_FAIL);
                    }
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    sciencePersonBo.setCreatedate(dateFormat.format(date));
                    sciencePersonBo.setId(IdUtils.simpleUUID());
                    sciencePersonBo.setSysUserId(sciencePersonBo.getId());
                    sciencePersonBo.setCheckstatus("-1");
                    int row = sciencePersonMapper.insert(sciencePersonBo);
                    SysUser user=new SysUser();
                    user.setDefaultRoleId(ROLE_BIZ_KYRY_ID);
                    user.setUserName(sciencePersonBo.getAccount());
                    user.setNickName(sciencePersonBo.getName());
                    user.setEmail(sciencePersonBo.getEmail());
                    user.setPhonenumber(sciencePersonBo.getMobile());
                    user.setSex(sciencePersonBo.getSexId());
                    user.setUserRealId(sciencePersonBo.getId());
                    user.setDeptRealId(sciencePersonBo.getUnitId());
                    SciencePersonVo sciencePersonVo=new SciencePersonVo();
                    sciencePersonVo.setId(sciencePersonBo.getId());
                    List<SysUser> list = sciencePersonMapper.personList(sciencePersonVo);
                    List<Long> deptId=list.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                    user.setDeptId(deptId.get(0));
                    iSysUserService.insertUser(user);
                    if(row==1){
                        return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                    }else {
                        sciencePersonMapper.deleteById(sciencePersonBo);
                        return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
                    }
                }
                case 1:{
                    //提交
                    Integer account=sciencePersonMapper.accountList(sciencePersonBo);
                    if(account>0){
                        return AjaxResult.error(BizProcessMessages.ACCOUNT_FAIL);
                    }
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    sciencePersonBo.setCreatedate(dateFormat.format(date));
                    sciencePersonBo.setId(IdUtils.simpleUUID());
                    sciencePersonBo.setSysUserId(sciencePersonBo.getId());
                    sciencePersonBo.setCheckstatus("1");
                    sciencePersonMapper.insert(sciencePersonBo);
                    SysUser user=new SysUser();
                    user.setDefaultRoleId(ROLE_BIZ_KYRY_ID);
                    user.setUserName(sciencePersonBo.getAccount());
                    user.setNickName(sciencePersonBo.getName());
                    user.setEmail(sciencePersonBo.getEmail());
                    user.setPhonenumber(sciencePersonBo.getMobile());
                    user.setSex(sciencePersonBo.getSexId());
                    user.setUserRealId(sciencePersonBo.getId());
                    user.setDeptRealId(sciencePersonBo.getUnitId());
                    SciencePersonVo sciencePersonVo=new SciencePersonVo();
                    sciencePersonVo.setId(sciencePersonBo.getId());
                    List<SysUser> list = sciencePersonMapper.personList(sciencePersonVo);
                    List<Long> deptId=list.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                    user.setDeptId(deptId.get(0));
                    iSysUserService.insertUser(user);
                    processInstanceId = approvalApi.businessEntryApproval(sciencePersonBo.getId(), "科研人员");
                    if(!StringUtils.isNotBlank(processInstanceId)){
                        //发起流程并返回示例id
                        //保存成功但流程实例id为空 -> 发起流程失败
                        sciencePersonBo.setCheckstatus("-1");
                        sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                        return AjaxResult.warn(BizProcessMessages.SAVE_PARTIAL_SUCCESS);
                    }else{
                        return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                    }
                }
                case 2:{
                    Integer account=sciencePersonMapper.accountList(sciencePersonBo);
                    if(account>0){
                        return AjaxResult.error(BizProcessMessages.ACCOUNT_FAIL);
                    }
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    sciencePersonBo.setCreatedate(dateFormat.format(date));
                    sciencePersonBo.setId(IdUtils.simpleUUID());
                    sciencePersonBo.setSysUserId(sciencePersonBo.getId());
                    sciencePersonBo.setCheckstatus("2");
                    sciencePersonBo.setProcessInstanceId("0");
                    int row = sciencePersonMapper.insert(sciencePersonBo);
                    SysUser user=new SysUser();
                    user.setDefaultRoleId(ROLE_BIZ_KYRY_ID);
                    user.setUserName(sciencePersonBo.getAccount());
                    user.setNickName(sciencePersonBo.getName());
                    user.setEmail(sciencePersonBo.getEmail());
                    user.setPhonenumber(sciencePersonBo.getMobile());
                    user.setSex(sciencePersonBo.getSexId());
                    user.setUserRealId(sciencePersonBo.getId());
                    user.setDeptRealId(sciencePersonBo.getUnitId());
                    SciencePersonVo sciencePersonVo=new SciencePersonVo();
                    sciencePersonVo.setId(sciencePersonBo.getId());
                    List<SysUser> list = sciencePersonMapper.personList(sciencePersonVo);
                    List<Long> deptId=list.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                    user.setDeptId(deptId.get(0));
                    iSysUserService.insertUser(user);
                    if(row==1){
                        return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                    }else {
                        return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
                    }
                    }
            }
        }
        return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
    }

        public AjaxResult updatePersonList(SciencePersonBo sciencePersonBo) {
            String processInstanceId = "";
            if(sciencePersonBo != null){
                Integer submitType = sciencePersonBo.getSubmitType();
                switch (submitType) {
                    case -1: {
                        String checkStatus = sciencePersonBo.getCheckstatus();
                        if( StringUtils.isNotBlank(checkStatus)&&checkStatus.equals("1")){
                            //保存状态
                            Date date = new Date();
                            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            sciencePersonBo.setLasteditdate(dateFormat.format(date));
                            int row=sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                            User user=new User();
                            user.setNickName(sciencePersonBo.getName());
                            user.setEmail(sciencePersonBo.getEmail());
                            user.setPhonenumber(sciencePersonBo.getMobile());
                            user.setSex(sciencePersonBo.getSexId());
                            user.setDeptRealId(sciencePersonBo.getUnitId());
                            SciencePersonVo sciencePersonVo=new SciencePersonVo();
                            sciencePersonVo.setId(sciencePersonBo.getId());
                            List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
                            List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
                            user.setUserId(userId.get(0));
                            List<SysUser> list1 = sciencePersonMapper.personList(sciencePersonVo);
                            List<Long> deptId=list1.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                            user.setDeptId(deptId.get(0));
                            userMapper.update(user,new UpdateWrapper<User>().eq("user_id",user.getUserId()));
                            if(row==1){
                                return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                            }else {
                                return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
                            }
                        }else {
                            //暂存：新建编辑都只保存信息，不做任何其他操作
                            Date date = new Date();
                            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            sciencePersonBo.setLasteditdate(dateFormat.format(date));
                            sciencePersonBo.setCheckstatus("-1");
                            sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                            User user=new User();
                            user.setNickName(sciencePersonBo.getName());
                            user.setEmail(sciencePersonBo.getEmail());
                            user.setPhonenumber(sciencePersonBo.getMobile());
                            user.setSex(sciencePersonBo.getSexId());
                            user.setDeptRealId(sciencePersonBo.getUnitId());
                            SciencePersonVo sciencePersonVo=new SciencePersonVo();
                            sciencePersonVo.setId(sciencePersonBo.getId());
                            List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
                            List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
                            user.setUserId(userId.get(0));
                            List<SysUser> list1 = sciencePersonMapper.personList(sciencePersonVo);
                            List<Long> deptId=list1.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                            user.setDeptId(deptId.get(0));
                            int row=userMapper.update(user,new UpdateWrapper<User>().eq("user_id",user.getUserId()));
                            if(row==1){
                                return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                            }else {

                                return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
                            }
                        }
                    }
                    case 1:{
                        Date date = new Date();
                        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        sciencePersonBo.setLasteditdate(dateFormat.format(date));
                        sciencePersonBo.setCheckstatus("1");
                        int row=sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                        User user=new User();
                        user.setNickName(sciencePersonBo.getName());
                        user.setEmail(sciencePersonBo.getEmail());
                        user.setPhonenumber(sciencePersonBo.getMobile());
                        user.setSex(sciencePersonBo.getSexId());
                        user.setDeptRealId(sciencePersonBo.getUnitId());
                        SciencePersonVo sciencePersonVo=new SciencePersonVo();
                        sciencePersonVo.setId(sciencePersonBo.getId());
                        List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
                        List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
                        user.setUserId(userId.get(0));
                        List<SysUser> list1 = sciencePersonMapper.personList(sciencePersonVo);
                        List<Long> deptId=list1.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                        user.setDeptId(deptId.get(0));
                        userMapper.update(user,new UpdateWrapper<User>().eq("user_id",user.getUserId()));
                        processInstanceId = approvalApi.businessEntryApproval(sciencePersonBo.getId(), "科研人员");
                        if(!StringUtils.isNotBlank(processInstanceId)){
                            //发起流程并返回示例id
                            //保存成功但流程实例id为空 -> 发起流程失败
                            sciencePersonBo.setCheckstatus("-1");
                            sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                            return AjaxResult.warn(BizProcessMessages.SAVE_PARTIAL_SUCCESS);
                        }else{
                            return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                        }
                    }
                    case 2:{
                        String checkStatus = sciencePersonBo.getCheckstatus();
                        if( StringUtils.isNotBlank(checkStatus)&&checkStatus.equals("-1")){
                            //保存并通过（管理员）：审核中且是当前审核人-》调流程接口；直接通过-》实例id为0
                            Date date = new Date();
                            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            sciencePersonBo.setLasteditdate(dateFormat.format(date));
                            sciencePersonBo.setProcessInstanceId("0");
                            sciencePersonBo.setCheckstatus("2");
                            int row=sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));
                            User user=new User();
                            user.setNickName(sciencePersonBo.getName());
                            user.setEmail(sciencePersonBo.getEmail());
                            user.setPhonenumber(sciencePersonBo.getMobile());
                            user.setSex(sciencePersonBo.getSexId());
                            user.setDeptRealId(sciencePersonBo.getUnitId());
                            SciencePersonVo sciencePersonVo=new SciencePersonVo();
                            sciencePersonVo.setId(sciencePersonBo.getId());
                            List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
                            List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
                            user.setUserId(userId.get(0));
                            List<SysUser> list1 = sciencePersonMapper.personList(sciencePersonVo);
                            List<Long> deptId=list1.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                            user.setDeptId(deptId.get(0));
                            userMapper.update(user,new UpdateWrapper<User>().eq("user_id",user.getUserId()));
                            if(row==1){
                                return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                            }else {
                                return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
                            }
                        }else {
                            Date date = new Date();
                            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            sciencePersonBo.setLasteditdate(dateFormat.format(date));
                            int row=sciencePersonMapper.update(sciencePersonBo,new UpdateWrapper<SciencePersonBo>().eq("ID",sciencePersonBo.getId()));

                            //根据流程实例id获取taskid
                            try{
                                //获取当前用户所有的代办列表
                                ProcessConfig processConfig = processService.getProcessByModelName("科研人员");
                                FlowQueryVo queryVo = new FlowQueryVo();
                                queryVo.setProcessDefinitionKey(processConfig.getProcessKey());
                                // 获取流程任务列表,Map<instanceId, taskId>
                                Map<String, String> instanceTaskMap = flowTaskService.todoListBydefKey_Api(queryVo);
                                BpmTaskApproveReqVO bta = new BpmTaskApproveReqVO();
                                bta.setId(instanceTaskMap.get(sciencePersonBo.getProcessInstanceId()));
                                bta.setReason(SecurityUtils.getNickName() + "保存并通过");
                                flowTaskService.approveTask(SecurityUtils.getUserId(), bta);
                            }catch (Exception exception){
                                String ex = exception.getMessage();
                            }
                            User user=new User();
                            user.setNickName(sciencePersonBo.getName());
                            user.setEmail(sciencePersonBo.getEmail());
                            user.setPhonenumber(sciencePersonBo.getMobile());
                            user.setSex(sciencePersonBo.getSexId());
                            user.setDeptRealId(sciencePersonBo.getUnitId());
                            SciencePersonVo sciencePersonVo=new SciencePersonVo();
                            sciencePersonVo.setId(sciencePersonBo.getId());
                            List<SysUser> list = sciencePersonMapper.userIdList(sciencePersonVo);
                            List<Long> userId=list.stream().map(SysUser::getUserId).collect(Collectors.toList());
                            user.setUserId(userId.get(0));
                            List<SysUser> list1 = sciencePersonMapper.personList(sciencePersonVo);
                            List<Long> deptId=list1.stream().map(SysUser::getDeptId).collect(Collectors.toList());
                            user.setDeptId(deptId.get(0));
                            userMapper.update(user,new UpdateWrapper<User>().eq("user_id",user.getUserId()));

                            //当前登录人修改自己信息时，要更新用户信息
                            try{
                                LoginUser loginUser = SecurityUtils.getLoginUser();
                                if (loginUser.getUser().getUserName().equals(sciencePersonBo.getAccount())) {
                                    loginUser.getUser().setNickName(sciencePersonBo.getName());
                                    loginUser.getUser().setEmail(sciencePersonBo.getEmail());
                                    loginUser.getUser().setPhonenumber(sciencePersonBo.getMobile());
                                    loginUser.getUser().setDeptId(deptId.get(0));
                                    loginUser.getUser().setDeptRealId(sciencePersonBo.getUnitId());
                                    loginUser.getUser().setDept(deptService.selectDeptById(deptId.get(0)));
                                    tokenService.setLoginUser(loginUser);
                                }
                            }catch (Exception ex)
                            {}

                            return AjaxResult.success(BizProcessMessages.SAVE_SUCCESS);
                        }
                    }
                }
            }
            return AjaxResult.error(BizProcessMessages.SAVE_FAIL);
    }

    public  List personDetails(SciencePersonVo sciencePersonVo) {
        String currentRoleKey = CurrentRoleUtils.getCurrentRoleKey();
        if(currentRoleKey.equals("biz_kyms")){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            String[] unitAdminScopeRealList = user.getUnitAdminScopeReal().split(",");
            sciencePersonVo.setUnitAdminScopeRealList(unitAdminScopeRealList);
        }
        List<SciencePersonBo> list = sciencePersonMapper.selectPersonDetails(sciencePersonVo);
        return list;
    }

    public  List personDetailsView(SciencePersonVo sciencePersonVo) {
        List<SciencePersonBo> list = sciencePersonMapper.selectPersonDetails(sciencePersonVo);
        return list;
    }

    public  ArrayList<Map<String,String>> processCount(SciencePersonVo sciencePersonVo) {
        String currentRoleKey = CurrentRoleUtils.getCurrentRoleKey();
        if(currentRoleKey.equals("biz_kyms")){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            String[] unitAdminScopeRealList = user.getUnitAdminScopeReal().split(",");
            sciencePersonVo.setUnitAdminScopeRealList(unitAdminScopeRealList);
        }
        String a = sciencePersonMapper.processAllCount(sciencePersonVo).toString();
        String b = sciencePersonMapper.processSubmitCount(sciencePersonVo).toString();
        String c = sciencePersonMapper.processReturnCount(sciencePersonVo).toString();
        String d = sciencePersonMapper.processPassCount(sciencePersonVo).toString();
        Map<String,String> map1 = new HashMap<>();
        map1.put("name","全部");
        map1.put("count",a);
        map1.put("code","");
        Map<String,String> map2 = new HashMap<>();
        map2.put("name","审批通过");
        map2.put("count",d);
        map2.put("code","2");
        Map<String,String> map3 = new HashMap<>();
        map3.put("name","审批不通过");
        map3.put("count",c);
        map3.put("code","3");
        Map<String,String> map4 = new HashMap<>();
        map4.put("name","审批中");
        map4.put("count",b);
        map4.put("code","1");
        ArrayList<Map<String,String>> allList = new ArrayList<>();
        allList.add(map1);
        allList.add(map2);
        allList.add(map3);
        allList.add(map4);
        return allList;
    }

    public List<UserEntity> officeContact() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        Set<Long> a=new HashSet<>();
        a.add(ROLE_BIZ_KYMS_ID);
        a.add(ROLE_BIZ_KYCGLY_ID);
        Set<Long>  list = iSysRoleService.selectUserIdsByRoleIds(a, user.getDeptId());
        List<UserEntity> sysRoleList1=new ArrayList<>();
        for (Long num : list) {
            SciencePersonVo sciencePersonVo=new SciencePersonVo();
            sciencePersonVo.setDeptId(user.getDeptId());
            sciencePersonVo.setUserId(num);
            sciencePersonVo.setRoleId(ROLE_BIZ_KYMS_ID);
            sciencePersonVo.setRoleIds(ROLE_BIZ_KYCGLY_ID);
            List<UserEntity> sysRoleList=sciencePersonMapper.userList(sciencePersonVo);
            sysRoleList1.addAll(sysRoleList);
        }
        return sysRoleList1;
    }

    public  List exportList(SciencePersonVo sciencePersonVo) {
        List<SciencePersonBo> list = sciencePersonMapper.exportList(sciencePersonVo);
        return list;
    }

}
